use std::sync::mpsc;
use std::thread;

fn main() {
    //创建一个通道
    let (sender, receiver) = mpsc::channel();
    //启动3个生产者
    for i in 0..3 {
        let tx = sender.clone(); //
        thread::spawn(move || {
            tx.send(i).expect("Failed to send message");
        });
    }
    //接收生产者的消息
    for _ in 0..3 {
        let received_message = receiver.recv().expect("Failed to receive message");
        println!("Received message: {}", received_message);
    }
}
